package com.lwd.util;

import java.io.Serializable;

public class Tuple4<A, B, C, D> implements Serializable {

    public final A a;
    public final B b;
    public final C c;
    public final D d;

    public Tuple4(A a, B b, C c, D d) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }

    @Override
    public int hashCode() {
        return (a == null ? 0 : a.hashCode()) * 31
                + (b == null ? 0 : b.hashCode())
                + (c == null ? 0 : c.hashCode())
                + (d == null ? 0 : d.hashCode());
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Tuple4)) {
            return false;
        }

        Tuple4 other = (Tuple4) obj;
        if (equals(this.a, other.a)
                && equals(this.b, other.b)
                && equals(this.c, other.c)
                && equals(this.d, other.d)) {
            return true;
        }

        return false;
    }

    private boolean equals(Object obj1, Object obj2) {
        return obj1 == obj2 || (obj1 != null && obj1.equals(obj2));
    }

    @Override
    public String toString() {
        return String.format("{a=%s, b=%s, c=%s, d=%s}", a, b, c, d);
    }
}